<?php

namespace app\common\model\Depot;

use think\Model;
use traits\model\SoftDelete;
class Back extends Model
{
    protected $name = 'depot_back';

    protected $autoWriteTimestamp = true;

    protected $createTime = 'createtime';

    protected $updateTime = false;

    use SoftDelete;
    protected $deleteTime = 'deletetime';
    protected $append = [
        'status_text', // 订单状态

    ];
    public function getStatusTextAttr($value, $data)
    {
        $status = $data['status'];

        switch ($status) {
            case '0':
                return '未审核';
            case '1':
                return '已审核，未收货';
            case '2':
                return '已收货，未入库';
            case '3':
                return '已入库';
            case '-1':
                return '审核不通过';
            default:
                return '未知状态';
        }
    }
    // 客户
    public function business()
    {
        return $this->belongsTo('app\common\model\Business\Business', 'busid', 'id', [], 'LEFT')->setEagerlyType(0);
    }
    //  物流
    public function expressquery()
    {
        return $this->belongsTo('app\admin\model\Expressquery', 'expressid', 'id', [], 'LEFT')->setEagerlyType(0);
    }
    //  区
    public function districts()
    {
        return $this->belongsTo('app\common\model\Region\Region', 'district', 'code', [], 'LEFT')->setEagerlyType(0);
    }
    //  市
    public function citys()
    {
        return $this->belongsTo('app\common\model\Region\Region', 'city', 'code', [], 'LEFT')->setEagerlyType(0);
    }
    //  省
    public function provinces()
    {
        return $this->belongsTo('app\common\model\Region\Region', 'province', 'code', [], 'LEFT')->setEagerlyType(0);
    }
    // 销售员
    public function sale()
    {
        return $this->belongsTo('app\common\model\Admin', 'adminid', 'id', [], 'LEFT')->setEagerlyType(0);
    }
    // 入库人员
    public function stroman()
    {
        return $this->belongsTo('app\common\model\Admin', 'stromanid', 'id', [], 'LEFT')->setEagerlyType(0);
    }
    // 审核员
    public function review()
    {
        return $this->belongsTo('app\common\model\Admin', 'reviewerid', 'id', [], 'LEFT')->setEagerlyType(0);
    }
}
